package service

import (
	"context"
	"core/dao"
	"core/entity"
	"core/repository"
)

type UserService struct {
	userDao *dao.UserDao
}

// FindUserByUid 根据 UID 查询用户信息
func (s *UserService) FindUserByUid(ctx context.Context, uid string) (*entity.User, error) {
	return s.userDao.FindUserByUid(ctx, uid)
}

func (s *UserService) Save(ctx context.Context, user *entity.User) error {
	return s.userDao.Save(ctx, user)
}

func (s *UserService) UpdateUserAddressByUid(uid string, param entity.UpdateUserAddressReq) error {
	user := &entity.User{
		Uid:      uid,
		Address:  param.Address,
		Location: param.Location,
	}
	return s.userDao.UpdateUserAddressById(context.TODO(), user)
}

func NewUserService(repo *repository.DbManager) *UserService {
	return &UserService{
		userDao: dao.NewUserDao(repo),
	}
}
